import 'dart:convert';

T? asT<T>(dynamic value) {
  if (value is T) {
    return value;
  }
  return null;
}

class LocationPoi {
  LocationPoi({
    this.name,
    this.id,
    this.location,
    this.type,
    this.typecode,
    this.pname,
    this.cityname,
    this.adname,
    this.address,
    this.pcode,
    this.citycode,
    this.adcode,
  });

  factory LocationPoi.fromJson(Map<String, dynamic> jsonRes) => LocationPoi(
        name: asT<String?>(jsonRes['name']),
        id: asT<String?>(jsonRes['id']),
        location: asT<String?>(jsonRes['location']),
        type: asT<String?>(jsonRes['type']),
        typecode: asT<String?>(jsonRes['typecode']),
        pname: asT<String?>(jsonRes['pname']),
        cityname: asT<String?>(jsonRes['cityname']),
        adname: asT<String?>(jsonRes['adname']),
        address: asT<String?>(jsonRes['address']),
        pcode: asT<String?>(jsonRes['pcode']),
        citycode: asT<String?>(jsonRes['citycode']),
        adcode: asT<String?>(jsonRes['adcode']),
      );

  String? name;
  String? id;
  String? location;
  String? type;
  String? typecode;
  String? pname;
  String? cityname;
  String? adname;
  String? address;
  String? pcode;
  String? citycode;
  String? adcode;

  @override
  String toString() {
    return jsonEncode(this);
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'name': name,
        'id': id,
        'location': location,
        'type': type,
        'typecode': typecode,
        'pname': pname,
        'cityname': cityname,
        'adname': adname,
        'address': address,
        'pcode': pcode,
        'citycode': citycode,
        'adcode': adcode,
      };

  LocationPoi clone() => LocationPoi.fromJson(
      asT<Map<String, dynamic>>(jsonDecode(jsonEncode(this)))!);
}
